//
//  DFTypePool.m
//  dfutil
//
//  Created by Tom Booth on 01/07/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "DFTypePool.h"
#import "DFParameter.h"

@interface DFTypePool(PrivateMethods)

+ (NSUInteger) hashArray:(NSArray*) array;

@end



@implementation DFTypePool

NSMutableDictionary *type_cache;



+ (NSString*) generateTypeForParameters:(NSArray*) parameters {
	
	
	
	return [NSString stringWithFormat: @"%d", [DFTypePool hashArray:parameters]];
}




+ (NSUInteger) hashArray:(NSArray*) array {
	
	NSUInteger hashVal = 0;
	
	for (DFParameter *obj in array) {
		hashVal = hashVal + [obj hashMe];
	}
	
	hashVal += [array count];
	
	// testing stuff
	if (type_cache== NULL) { type_cache = [[NSMutableDictionary alloc] init]; }
	
	NSNumber *hashNum = [NSNumber numberWithInteger:hashVal];
	
	if ([type_cache objectForKey:hashNum] == NULL) { [type_cache setObject:[NSNumber numberWithInteger:1] forKey:hashNum]; }
	else { 
		int val = [[type_cache objectForKey:hashNum] intValue];
		val++;
		[type_cache setObject:[NSNumber numberWithInteger:val] forKey:hashNum];
	}
	
	return hashVal;
	
}


+ (void) printPool {
	NSArray *keys = [type_cache allKeys];
	
	for (NSNumber *num in keys) {
		NSLog(@"%d: %d\n",[num intValue],[[type_cache objectForKey:num] intValue]);
	}
}

@end
